package cn.bluemobi.app.controller.shoppingCart;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.app.core.controller.AppBaseController;
import cn.bluemobi.app.entity.output.ShoppingCart;
import cn.bluemobi.app.service.ShoppingCartService;
import cn.bluemobi.common.core.dto.Dto;
import cn.bluemobi.common.core.dto.ListDto;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/shoppingCart")
@Api(description = "购物车", value = "shoppingCart")
public class ShoppingCartController extends AppBaseController {

	@Autowired
	private ShoppingCartService shoppingCartService;

	@ApiOperation(value = "添加购物车", httpMethod = "POST")
	@RequestMapping("/addShoppingCart")
	@ResponseBody
	public Dto<Object> addShoppingCart(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("商品ID") @RequestParam("commodityId") String commodityId,
			@ApiParam("商品规格ID") @RequestParam("specificationId") String specificationId,
			@ApiParam("数量") @RequestParam("quantity") String quantity) {
		return shoppingCartService.addShoppingCart(memberId, commodityId,
				specificationId, quantity);
	}

	@ApiOperation(value = "修改购物车数量", httpMethod = "POST")
	@RequestMapping("/updateShoppingCartQuantity")
	@ResponseBody
	public Dto<Object> updateShoppingCartQuantity(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("购物车ID（多个逗号隔开）") @RequestParam("shoppingCartIds") String shoppingCartIds,
			@ApiParam("数量（多个逗号隔开）") @RequestParam("quantitys") String quantitys) {
		return shoppingCartService.updateShoppingCartQuantity(memberId,
				shoppingCartIds, quantitys);
	}

	@ApiOperation(value = "删除购物车", httpMethod = "POST")
	@RequestMapping("/deleteShoppingCarts")
	@ResponseBody
	public Dto<Object> deleteShoppingCarts(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("购物车ID多个逗号隔开") @RequestParam("shoppingCartIds") String shoppingCartIds) {
		return shoppingCartService.deleteShoppingCarts(memberId,
				shoppingCartIds);
	}

	@RequestMapping("/findShoppingCartList")
	@ApiOperation(value = "查询购物车", httpMethod = "POST")
	@ResponseBody
	public ListDto<ShoppingCart> findShoppingCartList(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId) {
		return shoppingCartService.findShoppingCartList(memberId);
	}

}
